﻿using System;
using System.Collections.Generic;
using System.Data;
using Smatime.Web.DAO.SmatimeDatasetTableAdapters;
using Smatime.Web.Models;

namespace Smatime.Web.DAO
{
    public class TotalOfMonthRepository :
        BaseRepository<TotalOfMonth, SmatimeDataset.TotalOfMonthDataTable, TotalOfMonthTableAdapter>
    {
        /// <summary>
        ///     get total working of staff by Staff id
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public IEnumerable<TotalOfMonth> GetTotalWorkByStaffId(long id, DateTime month)
        {
            using (var adapter = new TotalOfMonthTableAdapter())
            {
                using (var table = adapter.GetDataBy(id, month))
                {
                    var list = new List<TotalOfMonth>();
                    foreach (DataRow row in table.Rows)
                    {
                        var WorkTotalOfStaff = new TotalOfMonth();
                        WorkTotalOfStaff.FromDataRow(row);
                        list.Add(WorkTotalOfStaff);
                    }
                    return list;
                }
            }
        }
    }
}